package com.kjc.demo.rcservice.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kjc.demo.rcservice.bean.FileStoreBean;
import com.kjc.demo.rcservice.repository.FileStoreMapper;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
* 描述：FileStoreService 服务接口
* @author kangjichang
* @date 2018-12-03
*/

@EnablePaasMybatis
@MapperScan("com.kjc.demo.rcservice.repository")
@Service
public class FileStoreService extends BaseDao<FileStoreBean, FileStoreMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return FileStoreMapper.class.getName();
		}
		
		@Autowired
		private FileStoreMapper fileStoreMapper;
		
		public PaginationEntity<FileStoreBean> getPageFileStoreList(BasePage pageRequest, FileStoreBean fileStoreBean) {
			Page<FileStoreBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true);
			List<FileStoreBean> list = fileStoreMapper.getList(fileStoreBean);
			PaginationEntity<FileStoreBean> paginationEntity = new PaginationEntity<FileStoreBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveFileStore(FileStoreBean fileStoreBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = fileStoreMapper.insertFileStore(fileStoreBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateFileStore(FileStoreBean fileStoreBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = fileStoreMapper.updateFileStore(fileStoreBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public FileStoreBean getFileStoreDetail(String id) {
			return fileStoreMapper.getFileStoreDetail(id);
		}
		
		public boolean deleteFileStore(FileStoreBean fileStoreBean){
			return fileStoreMapper.deleteFileStore(fileStoreBean)>0;
		}
		
		/**
		 * doc_info和file_store关联inner查询，根据doc_info的主键查询记录
		 * */
		public FileStoreBean getDocFileStoreInfo(String id) {
			return fileStoreMapper.getDocFileStoreInfo(id);
		}
      
}